package com.example.foobar.controller;

import com.example.foobar.business.service.DaUserChangeRecordService;
import com.example.foobar.entity.DaUserChangeRecord;
import com.example.foobar.dao.service.DaUserChangeRecordDaoService;
import lombok.extern.slf4j.Slf4j;
import com.example.foobar.param.DaUserChangeRecordPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 新增用户数记录 控制器
 *
 * @author 郑英奔
 * @since 2021-06-19
 */
@Slf4j
@RestController
@RequestMapping("/daUserChangeRecord")
@Module("foobar")
@Api(value = "新增用户数记录API", tags = {"新增用户数记录"})
public class DaUserChangeRecordController extends BaseController {

    /**
     * 添加新增用户数记录
     */
    @PostMapping("/add")
    @OperationLog(name = "添加新增用户数记录", type = OperationLogType.ADD)
    @ApiOperation(value = "添加新增用户数记录", response = ApiResult.class)
    public ApiResult<Boolean> addDaUserChangeRecord(@Validated(Add.class) @RequestBody DaUserChangeRecord daUserChangeRecord) throws Exception {
        boolean flag = daUserChangeRecordService.saveDaUserChangeRecord(daUserChangeRecord);
        return ApiResult.result(flag);
    }

    @Autowired
    private DaUserChangeRecordService daUserChangeRecordService;

    /**
     * 修改新增用户数记录
     */
    @PostMapping("/update")
    @OperationLog(name = "修改新增用户数记录", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改新增用户数记录", response = ApiResult.class)
    public ApiResult<Boolean> updateDaUserChangeRecord(@Validated(Update.class) @RequestBody DaUserChangeRecord daUserChangeRecord) throws Exception {
        boolean flag = daUserChangeRecordService.updateDaUserChangeRecord(daUserChangeRecord);
        return ApiResult.result(flag);
    }

    /**
     * 删除新增用户数记录
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除新增用户数记录", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除新增用户数记录", response = ApiResult.class)
    public ApiResult<Boolean> deleteDaUserChangeRecord(@PathVariable("id") Long id) throws Exception {
        boolean flag = daUserChangeRecordService.deleteDaUserChangeRecord(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取新增用户数记录详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "新增用户数记录详情", type = OperationLogType.INFO)
    @ApiOperation(value = "新增用户数记录详情", response = DaUserChangeRecord.class)
    public ApiResult<DaUserChangeRecord> getDaUserChangeRecord(@PathVariable("id") Long id) throws Exception {
        DaUserChangeRecord daUserChangeRecord = daUserChangeRecordService.getById(id);
        return ApiResult.ok(daUserChangeRecord);
    }

    /**
     * 新增用户数记录分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "新增用户数记录分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "新增用户数记录分页列表", response = DaUserChangeRecord.class)
    public ApiResult<Paging<DaUserChangeRecord>> getDaUserChangeRecordPageList(@Validated @RequestBody DaUserChangeRecordPageParam daUserChangeRecordPageParam) throws Exception {
        Paging<DaUserChangeRecord> paging = daUserChangeRecordService.getDaUserChangeRecordPageList(daUserChangeRecordPageParam);
        return ApiResult.ok(paging);
    }

}

